//
//  UIDevice+Ex.m
//  WeChatHelper
//
//  Created by Guo Rui on 2017/12/8.
//  Copyright © 2017年 TimeFace. All rights reserved.
//

#import "UIDevice+Ex.h"
#include <mach/mach.h>

@implementation UIDevice (Ex)

- (int64_t)memoryUsed {
    mach_port_t host_port = mach_host_self();
    mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
    vm_size_t page_size;
    vm_statistics_data_t vm_stat;
    kern_return_t kern;
    
    kern = host_page_size(host_port, &page_size);
    if (kern != KERN_SUCCESS) return -1;
    kern = host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size);
    if (kern != KERN_SUCCESS) return -1;
    return page_size * (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count);
}


@end
